#include <retro.h>
#include "retro.creator.h"

using namespace Retro::Creator::Editor;

INT gArrayZoom[] = { 50, 75, 100, 150, 200 };

// CONSTRUCTION ---------------------------------------------------------------

EditorBase::EditorBase(Data::ResourceType iType) :
  mToolBar(NULL),
  mResource(NULL),
  mType(iType)
{
  mMenuZoom.createPopup();

  Array_ForEachI(i, gArrayZoom)
  {
    TCHAR wText[RETRO_MAXTEXT];

    _stprintf(wText, _T("%d %%"), gArrayZoom[i]);
    mMenuZoom.append(i + 1, wText);
  }
}

EditorBase::~EditorBase()
{
  mMenuZoom.destroy();
}

// NOTIFY ---------------------------------------------------------------------

VOID  EditorBase::initToolbar()
{
  TCHAR wText[RETRO_MAXTEXT];

  _stprintf(wText, _T("%d %%"), getZoom());
  getToolBar()->setItemText(wText, EditorItemZoom);
}

VOID  EditorBase::onNotify(Event::NotifyEvent& iEvent)
{
  ToolBarNotify* wToolbarData = (ToolBarNotify*)iEvent.data;

  switch (iEvent.data->idFrom)
  {
  case EditorWindowToolbar:
    switch (wToolbarData->itemID)
    {
    case EditorItemZoom:
      setZoom(gArrayZoom[wToolbarData->value - 1]);
      break;
    default:
      onToolbar(wToolbarData);
      break;
    }
    break;
  }

  Window::onNotify(iEvent);
}

VOID  EditorBase::setZoom(INT value)
{
  TCHAR wText[RETRO_MAXTEXT];

  _stprintf(wText, _T("%d %%"), value);

  if (getToolBar())
    getToolBar()->setItemText(wText, EditorItemZoom);
}

VOID  EditorBase::setResource(Data::Resource* iValue)
{
  if (mResource)
    mResource->setClosed();

  if (mResource = iValue)
    mResource->setOpened();
}
